import * as bm from "/js/baseModule.js";

export class Module extends bm.baseModule {
    constructor(view) {
        super(view);
        let that = this;
        this.levelInfo = '';
        this.user = {};
        this._friendData = [];

        //套餐详情渲染
        let supplierCnt = globalData.supplier_cnt;
        let userinfo = globalData.user;
        let province = globalData.province;
        that.levelInfo = new Vue({
            el: '#addedService',
            data: {
                user: userinfo,
                supplier_cnt: supplierCnt,
                friends: 0,
                levelNum: 1,
            },
            computed: {
                percent: function () {
                    let num;
                    num = Math.floor((this.supplier_cnt.wechat - this.user.rank) / this.supplier_cnt.wechat * 100);
                    if (this.user.level == 40) {
                        return 1;
                    }
                    if (num <= 0) {
                        return 0;
                    } else if (num >= 90) {
                        return 89
                    }
                    return num;
                },
                personHead: function () {
                    let num;
                    num = Math.floor(this.supplier_cnt.wechat - this.user.rank);
                    if (this.user.level == 40) {
                        return 3;
                    }
                    if (num <= 0) {
                        return 0;
                    }

                    return num;
                }
            },
            methods: {
                choose: function (message) {
                    this.levelNum = message;
                }
            }
        })
    }
    afterInstall() {
        let that = this;
        let arr = [];
        api.getInviteList(function (json) {
            if (json) {
                that.levelInfo.friends = json.cnt;
                arr = json.not_bind_data.concat(json.data);
                arr.sort(function sortNumber(a, b) {
                    return b.invite_time - a.invite_time;
                });
                that._friendData = { "cnt": arr.length, "data": arr };
            }
        }, function (error) {
            if (error.status == 401) {

            } else {
                funs.tip(error.msg, "", "fail");
            }
        });
    }
    /*邀请好友明细列表*/
    _evt_openInvitation() {
        let that = this;
        location.hash = 'user/VipLevel/Invitation';
        funs.getModuleFuns('modules/user/Invitation.js',function (mod) {
            mod.setInvitationList(that._friendData);
        })
    }

}
